#!coding=utf-8
from django.db import models
from park.models import Park
from sa.models import SuperAdmin
# from enterprise_chemicals.models import Product
class User_admin(models.Model):
    username = models.CharField(u"用户名",max_length=30)
    password = models.CharField(u"密码",max_length=30)
    sa=models.ForeignKey(SuperAdmin)
    park=models.ForeignKey(Park)

    def getPark(self):
        return Park.objects.get(id=self.park.id)

    def getParkName(self):

        ps = Park.objects.filter(id=self.park.id)

        if len(ps) > 0 :
            return ps[0].name
        else:
            return '- 未初始化'

class User(models.Model):
    username = models.CharField(u"用户名",max_length=30)
    password = models.CharField(u"密码",max_length=30)

#行业分类名称
class Industry_classification_name(models.Model):
    name =  models.CharField(u"行业分类名称",max_length=100)
    user = models.ForeignKey(User)  
    
#登记注册类型名称
class Registration_type_name(models.Model):
    name =  models.CharField(u"登记注册类型名称",max_length=100)
    user = models.ForeignKey(User)

#企业
from park.models import Park as p
class Enterprise(models.Model):
    name = models.CharField(u"企业名称",max_length=30)
    disable = models.CharField(u"是否禁用",max_length=30,default=0)
    park=models.ForeignKey(p)
    user = models.ForeignKey(User)
    def getProductchem(self):
        from enterprise_chemicals.models import Product,ChemicalsRelative,IngredientsType
        ProductList=Product.objects.filter(enterprise=self)
        cr_type=IngredientsType.objects.get(name="产品信息")
        ChemicalsRelativeList=ChemicalsRelative.objects.filter(cr_type=cr_type)
        count=0
        for product in ProductList:
            for chemical in ChemicalsRelativeList:
                if chemical.che_entity==product.id:
                    count=count+1
        return count
    def getInterMeditatesProchem(self):
        from enterprise_chemicals.models import InterMeditatesPro,ChemicalsRelative,IngredientsType
        interMeditatesProList=InterMeditatesPro.objects.filter(enterprise=self)
        cr_type=IngredientsType.objects.get(name="中间产品信息")
        ChemicalsRelativeList=ChemicalsRelative.objects.filter(cr_type=cr_type)
        count=0
        for interMeditatesPro in interMeditatesProList:
            for chemical in ChemicalsRelativeList:
                if chemical.che_entity==interMeditatesPro.id:
                    count=count+1
        return count

    def getMaterialsChem(self):
        from enterprise_chemicals.models import Materials,ChemicalsRelative,IngredientsType
        Materialslist=Materials.objects.filter(enterprise=self)
        cr_type=IngredientsType.objects.get(name="原辅料信息")
        ChemicalsRelativeList=ChemicalsRelative.objects.filter(cr_type=cr_type)
        count=0
        for materials in Materialslist:
            for chemical in ChemicalsRelativeList:
                if chemical.che_entity==materials.id:
                    count=count+1
        return count

    def get10year(self):
        en=Environmental_emergencies.objects.get(enterprise=self)
        return en.drill
    def getGeoData(self):
        _ebi = Enterprise_basic_information.objects.filter(enterprise = self.id)
        
        if len(_ebi) > 0:
            return _ebi[0].geo_points, _ebi[0].geo_center_point, _ebi[0].geo_extent

        return False,False,False

    def getProductTotal(self):
        all_amount=0
        from enterprise_chemicals.models import Product
        list=Product.objects.filter(enterprise=self)
        for product in list:
            if product.year_amount=='':
                product.year_amount=0
            all_amount=int(product.year_amount)+all_amount
        return all_amount
    def getProductCount(self):
        from enterprise_chemicals.models import Product
        return len(Product.objects.filter(enterprise=self))

    def getMaterials(self):
        from enterprise_chemicals.models import Materials
        count=len(Materials.objects.filter(enterprise=self,is_dangerous="是"))
        return count

    def getMaterialscount(self):
        from enterprise_chemicals.models import Materials
        Mcount=Materials.objects.filter(enterprise=self)
        count=0
        for m in Mcount:
            count=count+m.input_amount
        return count

    def getFeatures(self):
        from enterprise_pollute.models import FeaturesPollu
        feat=FeaturesPollu.objects.filter(enterprise=self)
        return feat


    def getTz(self):
        from enterprise_pollute.models import FeaturesPollu
        return len(FeaturesPollu.objects.filter(enterprise=self))

    def getProductEmphasis(self):
        from enterprise_chemicals.models import Product
        return len(Product.objects.filter(enterprise=self,is_emphasis="是"))

    def getInformation(self):
        enterprise=Enterprise_basic_information.objects.filter(enterprise=self)
        if enterprise:
            enterprise=enterprise[0]
        return enterprise
    def getParkGeoData(self):
        if self.park.geo_points:
            return self.park.geo_points, self.park.geo_center_point
        else:
            return False,False
    def Getexhaust_let(self):
        from enterprise_pollute.models import Exhaust
        e=Exhaust.objects.filter(enterprise=self)
        if not e:
            r=0
        else:
            r=e[0].exhaust_let
        return r

    def getSO2(self):
        from enterprise_pollute.models import Exhaust,ExhaustTotalemission
        e=Exhaust.objects.filter(enterprise=self)
        if e:
            e=e[0]
        else:
            e=0
        resilt=ExhaustTotalemission.objects.filter(exhaust=e,type="1")
        if resilt:
            r=resilt[0].count
        else:
            r=0
        return r

    def getNOX(self):
        from enterprise_pollute.models import Exhaust,ExhaustTotalemission
        e=Exhaust.objects.filter(enterprise=self)
        if e:
            e=e[0]
            resilt=ExhaustTotalemission.objects.filter(exhaust=e,type="2")
            return resilt[0].count
        else:
            return 0


    def getfc(self):
        from enterprise_pollute.models import Exhaust,ExhaustTotalemission
        e=Exhaust.objects.filter(enterprise=self)
        if e:
            e=e[0]
            resilt=ExhaustTotalemission.objects.filter(exhaust=e,type="3")
            return resilt[0].count
        else:
            return 0


    def getzj(self):
        from enterprise_pollute.models import Exhaust,ExhaustTotalemission
        e=Exhaust.objects.filter(enterprise=self)
        if e:
            e=e[0]
            resilt=ExhaustTotalemission.objects.filter(exhaust=e,type="4")
            return resilt[0].count
        else:
            return 0

    def getfs(self):
        from enterprise_pollute.models import Water,WaterTotalemission
        w=Water.objects.filter(enterprise=self)
        if w:
            w[0].water_let
        else:
            return 0

    def getwt1(self):
        from enterprise_pollute.models import Water,WaterTotalemission
        w=Water.objects.filter(enterprise=self)
        if w:
            rs=WaterTotalemission.objects.filter(water=w[0],type="1")
            return rs[0].count
        else:
            return 0

    def getwt2(self):
        from enterprise_pollute.models import Water,WaterTotalemission
        w=Water.objects.filter(enterprise=self)
        if w:
            rs=WaterTotalemission.objects.filter(water=w[0],type="2")
            return rs[0].count
        else:
            return 0

    def getwt3(self):
        from enterprise_pollute.models import Water,WaterTotalemission
        w=Water.objects.filter(enterprise=self)
        if w:
            rs=WaterTotalemission.objects.filter(water=w[0],type="3")
            return rs[0].count
        else:
            return 0

    def getwt4(self):
        from enterprise_pollute.models import Water,WaterTotalemission
        w=Water.objects.filter(enterprise=self)
        if w:
            rs=WaterTotalemission.objects.filter(water=w[0],type="4")
            return rs[0].count
        else:
            return 0

    def getwt5(self):
        from enterprise_pollute.models import Water,WaterTotalemission
        w=Water.objects.filter(enterprise=self)
        if w:
            rs=WaterTotalemission.objects.filter(water=w[0],type="5")
            return rs[0].count
        else:
            return 0

    def getwt6(self):
        from enterprise_pollute.models import Water,WaterTotalemission
        w=Water.objects.filter(enterprise=self)
        if w:
            rs=WaterTotalemission.objects.filter(water=w[0],type="6")
            return rs[0].count
        else:
            return 0

    def getSolid(self):
        from enterprise_pollute.models import Solid
        s=Solid.objects.filter(enterprise=self)
        if s:
            return Solid.objects.filter(enterprise=self)[0].common_number
        else:
            return 0


    def getSolidw(self):
        from enterprise_pollute.models import Solid
        s=Solid.objects.filter(enterprise=self)
        if s:
            return Solid.objects.filter(enterprise=self)[0].wx_number
        else:
            return 0

class Enter_fill(models.Model):
    """
    填报批次
    """
    fill_key=models.CharField(u'唯一标识', max_length=30)
    fill_starttime=models.DateTimeField(u'本批次填报开始时间')
    fill_endtime=models.DateTimeField(u'本批次填报结束时间')
    create_at = models.DateTimeField(u'创建日期',auto_now_add=True)
    park=models.ForeignKey(Park)

    def getFillByPark(self):
        return Fill.objects.filter(enter_fill=self)

class Fill(models.Model):
    """
    企业在每次批次中的填报状态
    """
    SUB_STA=(
        ('no_submit',u'未提交'),
        ('submit',u'提交'),

    )
    enterprise = models.ForeignKey(Enterprise)
    status=models.CharField(u'状态',choices=SUB_STA, max_length=30)
    fill_time=models.DateTimeField(u'填报日期',auto_now=True)
    enter_fill=models.ForeignKey(Enter_fill)
#申报状态
class Application_status(models.Model):
    app_name = models.CharField(u'应用名称', max_length=30)
    app_status = models.CharField(u'应用状态', max_length=30, default=u'未确认')
    app_submit_time = models.DateTimeField(u'应用提交时间',auto_now_add=True)
    """
    填报key
    """
    app_key = models.CharField(u'唯一标识', max_length=30)
    fill=models.ForeignKey(Fill)
    enterprise = models.ForeignKey(Enterprise)
    app_url=models.CharField(u'地址',max_length=200)
    order=models.IntegerField()

class Fillpeopleinfo(models.Model):
    fill_people= models.CharField(u'填报人',max_length = 30)
    mail=models.CharField(u'邮箱',max_length = 300)
    local_phone=models.CharField(u'固定电话',max_length = 25)
    mobile_phone=models.CharField(u'移动电话',max_length = 25)
    fax=models.CharField(u'传真',max_length = 25)
    postal_code = models.CharField(u'邮政编码',max_length = 30)
    enterprise = models.ForeignKey(Enterprise)
    application_status=models.ForeignKey(Application_status)
    SUBMIT_STATUS=(
        ('1',u'提交'),
        ('2',u'暂存'),
    )
    submit_type=models.CharField(u'提交类型',choices=SUBMIT_STATUS,max_length = 30)
#基本信息
class Enterprise_basic_information(models.Model):
    enterprise_name = models.CharField(u"企业名称",max_length=30)
    organization_code = models.CharField(u'组织机构代码',max_length = 30)
    legal_representative = models.CharField(u'法定代表人',max_length = 30)
    # fill_people= models.CharField(u'填报人',max_length = 30)
    # mail=models.CharField(u'邮箱',max_length = 300)
    # local_phone=models.CharField(u'固定电话',max_length = 25)
    # mobile_phone=models.CharField(u'移动电话',max_length = 25)
    # fax=models.CharField(u'传真',max_length = 25)
    LICENSES_STATUS=(
        ('1', u'重点环境危化品企业'),
        ('2', u'其他危化品企业'),
        ('3', u'非化学品企业'),
    )
    enterprise_type=models.CharField(u'企业类型',choices=LICENSES_STATUS,max_length = 30)
    # postal_code = models.CharField(u'邮政编码',max_length = 30)
    company_contact = models.CharField(u'企业联系人',max_length = 30)
    company_contact_information = models.CharField(u'企业联系人联系方式',max_length = 100)
    legal_person = models.CharField(u'法人',max_length = 30)
    legal_person_information = models.CharField(u'企业法人联系方式',max_length = 100)
    registration_No = models.CharField(u"工商注册号",max_length=30)
    business_license_photocopy =models.FileField(u'营业执照复印件',upload_to= 'static\\upload\\%Y\\%m-%d',null=True,blank=True)
    operation_term = models.CharField(u'截止日期',max_length = 30)
    register_add0 = models.CharField(u"企业注册地址",max_length=20)
    register_add1 = models.CharField(u"企业注册地址",max_length=20)
    register_add2 = models.CharField(u"企业注册地址",max_length=20)
    register_add_detail = models.CharField(u"工商注册地址详细",max_length=100)
    facilities_add0 = models.CharField(u'生产设施地址',max_length = 30)
    facilities_add1 = models.CharField(u'生产设施地址',max_length = 30)
    facilities_add2 = models.CharField(u'生产设施地址',max_length = 30)
    facilities_add_detail = models.CharField(u'生产设施地址详细',max_length = 100)
    geo_points = models.TextField(u'地理位置点集合',default='')
    geo_center_point = models.CharField(u'地理位置中心点坐标',max_length=100, default='')
    lat= models.CharField(u'维度',max_length=100, default='')
    lon= models.CharField(u'经度',max_length=100, default='')
    geo_extent = models.TextField(u'地理比例尺',default='')

    industry_park_time = models.IntegerField(u"进入工业园区情况",default=0)
    industry_park_level = models.IntegerField(u'工业园区级别',default=0)

    industry_park_name = models.CharField(u"所在工业园区名称",max_length=20)
    industry_park_code = models.CharField(u'工业园区代码',max_length = 30)

    industry_name = models.CharField(u"行业分类名称",max_length=20)
    industry_code = models.CharField(u'行业分类代码',max_length = 30)

    register_name = models.CharField(u"登记注册类型名称",max_length=20)
    register_code = models.CharField(u'登记注册类型代码',max_length = 30)

    registered_capital = models.CharField(u"注册资金万",max_length=20)
    industrial_output = models.CharField(u'工业总产值(万)',max_length = 30)

    area = models.CharField(u"厂区面积",max_length=20)
    plane_layout = models.FileField(u'总平面布置图',upload_to= 'static\\upload\\%Y\\%m-%d',null=True,blank=True)
    enterprise_number = models.CharField(u'企业人数',max_length = 30)

    annual_produce_time = models.CharField(u"年生产时间（小时）",max_length=20)
    scale = models.IntegerField(u'企业规模',default=0)

    opening_time = models.CharField(u"开业时间",max_length=20)
    extension_time = models.CharField(u'最近改扩建时间',max_length = 30)
    SUBMIT_STATUS=(
        ('1',u'提交'),
        ('2',u'暂存'),
    )
    submit_type=models.CharField(u'提交类型',choices=SUBMIT_STATUS,max_length = 30)
    enterprise = models.ForeignKey(Enterprise)
    application_status=models.ForeignKey(Application_status)
    def getObj(self):
        _dict = {}
        _dict['id'] = int(self.id)
        _dict['enterprise_name'] = self.enterprise_name
        _dict['organization_code'] = self.organization_code
        _dict['legal_representative'] =  self.legal_representative
        
        _dict['company_contact'] = self.company_contact
        _dict['company_contact_information'] = self.company_contact_information
        _dict['legal_person'] = self.legal_person
        _dict['legal_person_information'] =  self.legal_person_information
        
        _dict['registration_No'] = self.registration_No
        _dict['business_license_photocopy'] = self.business_license_photocopy
        _dict['operation_term'] = self.operation_term

        _dict['parent_company'] = self.parent_company
        _dict['subordinate_relationship'] = self.subordinate_relationship
        _dict['sup_name'] = self.sup_name

        _dict['sup_organization_code'] = self.sup_organization_code
        _dict['register_add0'] = self.register_add0
        _dict['register_add1'] = self.register_add1
        _dict['register_add2'] = self.register_add2
        _dict['register_add_detail'] = self.register_add_detail
        _dict['facilities_add0'] = self.facilities_add0
        _dict['facilities_add1'] = self.facilities_add1
        _dict['facilities_add2'] = self.facilities_add2
        _dict['facilities_add_detail'] = self.facilities_add_detail

        _dict['administrative_area_code'] = self.administrative_area_code
        _dict['postal_code'] = self.postal_code

        _dict['industry_park_time'] = self.industry_park_time
        _dict['industry_park_level'] = self.industry_park_level
        _dict['industry_park_name'] = self.industry_park_name
        _dict['industry_park_code'] = self.industry_park_code



        _dict['industry_name'] = self.industry_name
        _dict['industry_code'] = self.industry_code

        _dict['register_name'] = self.register_name
        _dict['register_code'] = self.register_code


        _dict['registered_capital'] = self.registered_capital
        _dict['industrial_output'] = self.industrial_output
        _dict['area'] = self.area

        _dict['plane_layout'] = self.plane_layout
        _dict['enterprise_number'] = self.enterprise_number
        _dict['annual_produce_time'] = self.annual_produce_time

        _dict['scale'] = self.scale
        _dict['opening_time'] = self.opening_time
        _dict['extension_time'] = self.extension_time

        _dict['geo_points'] = self.geo_points if False else '[]'
        _dict['geo_center_point'] = self.geo_center_point if False else '[]'

        return _dict

#文档没有
#环境管理情况
class  Environmental_management(models.Model):
    #内部环境管理机构建立情况
    agency_exist = models.CharField(u'环境管理机构',max_length = 30)
    organization_name = models.CharField(u'机构名称',max_length = 30)
    number = models.CharField(u'机构人数',max_length = 30)
    person_in_charge = models.CharField(u'环保负责人',max_length = 30)
    phone = models.CharField(u'联系电话',max_length = 30)
    email = models.CharField(u'电子邮箱',max_length = 30)
    #环保制度制定情况
    protection_system = models.CharField(u'企业环保制度',max_length = 30)
    description  = models.CharField(u'主要环保制度描述',max_length = 30)
    #危险化学品档案建立情况
    ledger = models.CharField(u'是否建立危险化学品台账',max_length = 30)
    archives = models.CharField(u'是否建立环境管理档案',max_length = 30)
    extension_time = models.CharField(u'环境管理档案信息主要内容',max_length = 30)
    enterprise = models.ForeignKey(Enterprise)

    def getObj(self):
        _dict={}
        _dict['id'] = self.id
        _dict['agency_exist'] = self.agency_exist
        _dict['organization_name'] = self.organization_name
        _dict['number'] = self.number

        _dict['person_in_charge'] = self.person_in_charge
        _dict['phone'] = self.phone
        _dict['email'] = self.email

        _dict['protection_system'] = self.protection_system
        _dict['description'] = self.description
        _dict['ledger'] = self.ledger

        _dict['archives'] = self.archives
        _dict['extension_time'] = self.extension_time
        return _dict


# # 环境保护目标信息（菜单）
# class EnvironmentMenu(models.Model):
#     application_status=models.ForeignKey(Application_status)
#     SUBMIT_STATUS=(
#         ('1',u'提交'),
#         ('2',u'暂存'),
#     )
#     submit_type=models.CharField(u'提交类型',choices=SUBMIT_STATUS,max_length = 30)


#水环境保护目标
class  Water_environment(models.Model):
    water_exist = models.IntegerField(u'周边是否存在水环境保护目标')
    water_remark = models.CharField(u'备注',max_length = 200)
    enterprise = models.ForeignKey(Enterprise)
    application_status=models.ForeignKey(Application_status)
    SUBMIT_STATUS=(
        ('1',u'提交'),
        ('2',u'暂存'),
    )
    submit_type=models.CharField(u'提交类型',choices=SUBMIT_STATUS,max_length = 30)

    def getObj(self):
        _dict={}
        _dict['id'] = self.id
        _dict['water_exist'] = self.water_exist
        _dict['water_remark'] = self.water_remark
        return _dict
    
    
#水环境保护目标
class  Water_environment_detail(models.Model):
    water_name = models.CharField(u'水环境保护目标名称',max_length = 30)
    water_code = models.CharField(u'环境功能质量类别',max_length = 30)
    water_scale = models.CharField(u'方位',max_length = 30)
    water_distance = models.CharField(u'距离企业距离',max_length = 30)

    environment = models.ForeignKey(Water_environment)
    def getObj(self):
        _dict={}
        _dict['id'] = self.id
        _dict['water_exist'] = self.water_exist
        _dict['water_remark'] = self.water_remark
        return _dict    


#大气环境保护目标
class  Gas_environment(models.Model):
    gas_exist = models.IntegerField(u'周边是否存在大气环境保护目标')
    gas_remark = models.CharField(u'备注',max_length = 200)
    application_status=models.ForeignKey(Application_status)
    enterprise = models.ForeignKey(Enterprise)
    SUBMIT_STATUS=(
    ('1',u'提交'),
    ('2',u'暂存'),
    )
    submit_type=models.CharField(u'提交类型',choices=SUBMIT_STATUS,max_length = 30)
    def getObj(self):
        _dict={}
        _dict['id'] = self.id
        _dict['gas_exist'] = self.gas_exist
        _dict['gas_remark'] = self.gas_remark
        return _dict
#大气环境保护目标
class  Gas_environment_detail(models.Model):
    gas_name = models.CharField(u'大气环境保护目标名称',max_length = 30)
    gas_code = models.CharField(u'方位',max_length = 30)
    gas_scale = models.CharField(u'规模',max_length = 30)
    gas_type=models.CharField(u'环境功能质量类别',max_length = 230)
    gas_distance = models.CharField(u'距离厂界距离',max_length = 30)
    environment = models.ForeignKey(Gas_environment)
    def getObj(self):
        _dict={}
        _dict['id'] = self.id

        _dict['gas_name'] = self.gas_name
        _dict['gas_code'] = self.gas_code
        _dict['gas_scale'] = self.gas_scale
        _dict['gas_distance'] = self.gas_distance
        return _dict    

# 生态环境保护目标名称
class Ecological(models.Model):
    name=models.CharField(u'生态环境保护目标名称',max_length = 130)
    gas_code = models.CharField(u'方位',max_length = 30)
    gas_distance = models.CharField(u'距离厂界距离',max_length = 30)
    enterprise = models.ForeignKey(Enterprise)
    application_status=models.ForeignKey(Application_status)
    SUBMIT_STATUS=(
    ('1',u'提交'),
    ('2',u'暂存'),
    )
    submit_type=models.CharField(u'提交类型',choices=SUBMIT_STATUS,max_length = 30)
'''
法律法规遵守情况
一、获得的行政许可情况
'''
class Licenses(models.Model):
    LICENSES_STATUS=(
        ('1', u'环境影响评价文件批复'),
        ('2', u'建设项目竣工环境保护验收审批文件'),
        ('3', u'污染物排放许可证'),
        ('4',u'危险废物经营许可证'),
        ('5',u'危险化学品安全生产许可证'),
        ('6',u'危险化学品安全使用许可证'),
        ('7',u'工业产品生产许可证'),
    )
    file_name = models.CharField(u'许可文件名称',max_length = 30)
    serial_number = models.CharField(u'文号/编号',max_length = 30)
    issuing_authority = models.CharField(u'发证机关',max_length = 30)
    expiration = models.CharField(u'有效期限',max_length = 30)
    remark =  models.CharField(u'备注',max_length = 500)
    upload_file=models.FileField(upload_to='static\\upload\\%Y\\%m-%d',null=True,blank=True)
    upload_file_name = models.CharField(u'文件名',max_length = 30)
    type=models.CharField(u'许可证类型',choices=LICENSES_STATUS,max_length=500)
    application_status=models.ForeignKey(Application_status)
    enterprise = models.ForeignKey(Enterprise)
    SUBMIT_STATUS=(
    ('1',u'提交'),
    ('2',u'暂存'),
    )
    submit_type=models.CharField(u'提交类型',choices=SUBMIT_STATUS,max_length = 30)
    def getObj(self):
        _dict={}
        _dict['id'] = self.id
        _dict['file_ids'] = self.file_ids
        _dict['type_id'] = self.type_id
        _dict['serial_number'] = self.serial_number
        _dict['issuing_authority'] = self.issuing_authority
        _dict['expiration'] = self.expiration
        _dict['remark'] = self.remark
        return _dict


class Law_remark(models.Model):
    LAW_REMARK=(
        ('1',u'行政许可情况'),
        ('2',u'污染物达标排放情况'),)
    remark =  models.CharField(u'备注',max_length = 500)
    enterprise = models.ForeignKey(Enterprise)
    type=models.CharField(u'备注类型',choices=LAW_REMARK,max_length=500)

class Law_files(models.Model):
    FILE_TYPE=(
        ('1',u'行政许可情况'),
        ('2',u'污染物达标排放情况'),
        ('3',u'清洁生产审核情况'),
    )
    upload_file=models.FileField(upload_to='static\\upload\\%Y\\%m-%d',null=True,blank=True)
    file_name = models.CharField(u'文件名',max_length = 30)
    enterprise = models.ForeignKey(Enterprise)
    type=models.CharField(u'文件类型',choices=FILE_TYPE,max_length=500)


'''二、污染物达标排放情况'''
class Emissions(models.Model):
    EMS_TYPE=(
        ('1',u'废水'),
        ('2',u'废气'),
        ('3',u'噪声'),
    )
    SUBMIT_STATUS=(
    ('1',u'提交'),
    ('2',u'暂存'),
    )
    submit_type=models.CharField(u'提交类型',choices=SUBMIT_STATUS,max_length = 30)
    name = models.CharField(u'监测项目名称',max_length = 150)
    code = models.CharField(u'执行标准号',max_length = 60)
    level = models.CharField(u'执行级别', max_length = 600)
    status = models.CharField(u'达标情况',max_length = 60)
    type=models.CharField(u'类型',choices=EMS_TYPE,max_length=500)
    enterprise = models.ForeignKey(Enterprise)
    sm= models.CharField(u'不达标情况说明',max_length = 600)
    application_status=models.ForeignKey(Application_status)
'''
三、清洁生产审核情况
'''
class Cleaner_production(models.Model):
    enforcement = models.CharField(u'是否属于强制清洁生产审核单位',max_length = 30)
    launch = models.CharField(u'清洁生产审核开展情况',max_length = 30)
    evaluation = models.CharField(u'清洁生产审核评估情况',max_length = 30)
    acceptance = models.CharField(u'清洁生产审核验收情况',max_length = 30)
    most_recently = models.CharField(u'最近一次清洁生产审核评估或验收时间',max_length = 200)
    department = models.CharField(u'清洁生产审核评估或验收部门',max_length = 30)
    remark = models.CharField(u'备注',max_length = 200)
    enterprise = models.ForeignKey(Enterprise)
    application_status=models.ForeignKey(Application_status)
    SUBMIT_STATUS=(
    ('1',u'提交'),
    ('2',u'暂存'),
    )
    submit_type=models.CharField(u'提交类型',choices=SUBMIT_STATUS,max_length = 30)
    def getObj(self):
        _dict = {}
        _dict["id"] = self.id
        _dict["enforcement"] = self.enforcement
        _dict["launch"] = self.launch
        _dict["evaluation"] = self.evaluation
        _dict["acceptance"] = self.acceptance
        _dict["most_recently"] = self.most_recently
        _dict["department"] = self.department
        _dict["remark"] = self.remark

        _dict["proof_file"] = self.proof_file.name

        return _dict

'''
四、发环境事件应急预案
'''
class Environmental_emergencies(models.Model):
    file_ids = models.IntegerField(u'是否编制应急预案')
    preparation_time = models.CharField(u'编制时间',max_length = 30)
    is_record = models.IntegerField(u'应急预案是否备案')
    filing_time = models.CharField(u'备案时间及单位',max_length = 100)
    drill = models.IntegerField(u'近10年发生突发环境事件情况')
    drill_times = models.IntegerField(u'10年发生突发环境事件情况次数')
    remark = models.CharField(u'事件描述',max_length = 200)
    enterprise = models.ForeignKey(Enterprise)
    application_status=models.ForeignKey(Application_status)
    SUBMIT_STATUS=(
    ('1',u'提交'),
    ('2',u'暂存'),
    )
    submit_type=models.CharField(u'提交类型',choices=SUBMIT_STATUS,max_length = 30)
    def getObj(self):
        _dict = {}
        _dict["id"] = self.id
        _dict["file_ids"] = self.file_ids
        _dict["preparation_time"] = self.preparation_time
        _dict["is_record"] = self.is_record
        _dict["filing_time"] = self.filing_time
        _dict["drill"] = self.drill
        _dict["drill_times"] = self.drill_times
        _dict["remark"] = self.remark
        return _dict


'''五、环境污染事故情况'''
class Environmental_accident(models.Model):
    exist = models.CharField(u'三年内环境污染事故情况',max_length = 30)
    times = models.CharField(u'发生次数',max_length = 30)
    time = models.CharField(u'发生时间',max_length = 30)
    level = models.CharField(u'事故级别',max_length = 30)
    reason = models.CharField(u'事故原因',max_length = 30)
    influence = models.CharField(u'事故环境影响',max_length = 30)
    publishment = models.CharField(u'处罚情况',max_length = 30)
    enterprise = models.ForeignKey(Enterprise)
    def getObj(self):
        _dict = {}
        _dict["id"] = self.id
        _dict["exist"] = self.exist
        _dict["times"] = self.times
        _dict["time"] = self.time
        _dict["level"] = self.level
        _dict["reason"] = self.reason
        _dict["influence"] = self.influence
        _dict["publishment"] = self.publishment
        return _dict


'''六、环境信息公开情况'''
class Information_disclosure(models.Model):
    disclosure = models.CharField(u'信息公开情况',max_length = 30)
    times = models.CharField(u'公开时间',max_length = 30)
    time = models.CharField(u'公开方式',max_length = 30)
    level = models.CharField(u'公开内容',max_length = 30)
    remark = models.CharField(u'备注',max_length = 200)
    enterprise = models.ForeignKey(Enterprise)
    def getObj(self):
        _dict = {}
        _dict["id"] = self.id
        _dict["disclosure"] = self.disclosure
        _dict["times"] = self.times
        _dict["time"] = self.time
        _dict["level"] = self.level
        _dict["remark"] = self.remark
        return _dict

